package com.loft.controller;

import java.util.List;
import com.loft.comm.util.LogCenter;
import com.loft.model.face.HTTPCenter;
import com.loft.vo.renren.Vo;
import android.util.Log;

/**
 * @InterfaceName: ConnectionInterface.java
 * @Description:策略工厂，维持一个对ConAndGetInfo的引用
 * @Author: hebin
 * @CreateDate: 2011/12/12
 */
public class HTTPCenterController {
	private HTTPCenter _connection;
	private final String Tag = this.getClass().getName();

	// 采用反射的方式生成指定类
	public HTTPCenterController(String className) {
		try {
			Class<?> theClass = Class.forName(className);
			this._connection = (HTTPCenter) theClass.getConstructor()
					.newInstance();
		} catch (Exception e) {
			LogCenter.getInstance().error(Tag, e.toString());
			this._connection = null;
		}

	}

	// 采用反射的方式生成指定类
	public HTTPCenterController(String className, String uid) {
		try {
			Class<?> theClass = Class.forName(className);
			this._connection = (HTTPCenter) theClass.getConstructor(
					String.class).newInstance(uid);
		} catch (Exception e) {
			LogCenter.getInstance().error(Tag, e.toString());
			this._connection = null;
		}

	}

	// 采用反射的方式生成指定类
	public HTTPCenterController(String className, int page, int pageSize) {
		try {
			Class<?> theClass = Class.forName(className);
			this._connection = (HTTPCenter) theClass.getConstructor(
					Integer.class, Integer.class).newInstance(page, pageSize);
		} catch (Exception e) {
			Log.e("error", e.toString());
			this._connection = null;
		}

	}

	// // 采用反射的方式生成指定类
	// public HTTPServiceController(String theClass, List<String> urlList) {
	// try {
	// Class<?> theClass = Class.forName(theClass);
	// this._connection = (HTTPService) theClass.getConstructor(
	// List.class).newInstance(urlList);
	// } catch (Exception e) {
	// LogCenter.getInstance().error(Tag, e.toString());
	// this._connection = null;
	// }
	//
	// }

	public List<? extends Vo> doConnect() {
		if (_connection == null) {
			return null;
		}
		return _connection.parseJsonData(_connection
				.connectionAndGetJsonString());
	}
}
